function ContentScrpit(){
    this.init();
}

ContentScrpit.prototype = {
    init(){
        this.onMessage()
        //去backgroud获取spiderType
    },
    onMessage(){
        chrome.runtime.onMessage.addListener( (request, sender, sendResponse) => {
            if(request.cmd=='spider_taobao'){
                this.spiderTaobao()
            }
            sendResponse('content-script')
        });
    },
    spiderTaobao(){
        window.scrollTo(0,0)
        $('html,body').animate({scrollTop:9000}, 2000, ()=>{
            var items = $('#J_search_results .block-search-box'), item , target, json=[];
            $('.shop-title').each(function(){$(this).hover()})
            setTimeout(_=>{
                items.each(index => {
                    target = items.eq(index)
                    item = {
                        img: target.find('.pic-box img').attr('src'),
                        couponVal: target.find('.tag-coupon .money span').text(),
                        couponLeft: target.find('.tags-container .valign-m span').text(),
                        title: target.find('.content-title').attr('title'),
                        sellVolume: target.find('.box-content .content-line.clearfix.mt5 .fr .color-d span').text(),
                        seller: target.find('.shop-hd a span').text(),
                        category: target.find('.shop-category').text(),
                        rate: parseFloat(target.find('.box-content .content-line').last().find('.fl .number').text()),
                        commission: parseFloat(target.find('.box-content .content-line').last().find('.fr .number').text().replace('￥','')),
                        plat: target.find('.tag-tmall').size() ? '天猫': '淘宝'
                    }
                    json.push(item)
                })
                console.log(json)
            },1000)
        })
    }
}

new ContentScrpit()
